#include "Player.h"
#include "../Managers/GameManager.h"
#include "../Managers/InputManager.h"
#include "../Maps/Forest.h"

Player::Player()
	: GameObject(Vec2i(),'@', TCODColor::red)
{
}

Player::~Player()
{
}

void Player::init()
{
	auto forest = GameManager::getSingleton()->getForest();
	auto forest_center = forest->getMapSize() / 2;
	setPos(forest_center);

	auto input = GameManager::getSingleton()->getInputMgr();
	input->setKeyCallback(TCODK_LEFT,	0, [this](TCOD_key_t input) { this->translate(-1, 0); });
	input->setKeyCallback(TCODK_RIGHT,	0, [this](TCOD_key_t input) { this->translate( 1, 0); });
	input->setKeyCallback(TCODK_UP,		0, [this](TCOD_key_t input) { this->translate( 0,-1); });
	input->setKeyCallback(TCODK_DOWN,	0, [this](TCOD_key_t input) { this->translate( 0, 1); });
}

void Player::update()
{
	auto cell = GameManager::getSingleton()->getForest()->getCellAt(pos);
	if(cell == nullptr)
		return;
	auto console = GameManager::getSingleton()->getStoryConsole();
	console->print(0,0, ("You're walking on " + cell->terrainType->type).c_str());
}

void Player::render()
{
	/*auto console = GameManager::getSingleton()->getMapConsole();
	auto viewport_center = GameManager::getSingleton()->getMapViewport() / 2;
	console->putChar(viewport_center.x(), viewport_center.y(), tile, TCOD_BKGND_NONE);
	console->setCharForeground(viewport_center.x(), viewport_center.y(), color);*/
}
